package com.hxx.common.core.wcontour.util;


import com.hxx.common.core.wcontour.base.TrainData;

/**
 * 坐标转换工具类
 *
 * @author hxd
 */
public class CoordConverUtil {

    /**
     * 调转X轴，数据data为数组[x][y]
     * 效果为左右调转
     *
     * @param trainData
     */
    public static void converX(TrainData trainData) {
        double[][] data = trainData.getData();
        int _x = data.length;
        int _y = data[0].length;
        double[][] matrix = new double[_x][_y];
        for (int i = 0; i < _x; i++) {
            for (int j = 0; j < _y; j++) {
                matrix[_x - i - 1][j] = data[i][j];
            }
        }
        trainData.setData(matrix);
    }

    /**
     * 调转Y轴，数据data为数组[x][y]
     * 效果为上下调转
     *
     * @param trainData
     */
    public static void converY(TrainData trainData) {
        double[][] data = trainData.getData();
        int _x = data.length;
        int _y = data[0].length;
        double[][] matrix = new double[_x][_y];
        for (int i = 0; i < _x; i++) {
            for (int j = 0; j < _y; j++) {
                matrix[i][_y - j - 1] = data[i][j];
            }
        }
        trainData.setData(matrix);
    }

    /**
     * 转换数据data为数组[x][y]->[y][x]
     *
     * @param trainData
     */
    public static void converDataXY(TrainData trainData) {
        double[][] data = trainData.getData();
        int _x = data.length;
        int _y = data[0].length;
        double[][] matrix = new double[_y][_x];
        for (int i = 0; i < _x; i++) {
            for (int j = 0; j < _y; j++) {
                matrix[j][i] = data[i][j];
            }
        }
        trainData.setData(matrix);
    }

    /**
     * 数据data数组[y][x]转换 3*n 的二维数组,{0,{x,y,v}}按顺序是"x"组，"y"组,"值"组
     *
     * @param trainData
     */
    public static void converGridData(TrainData trainData) {
        double[][] data = trainData.getData();
        double[][] matrix = new double[trainData.getSize()[0] * trainData.getSize()[1]][3];
        double[] _x = trainData.get_X();
        double[] _y = trainData.get_Y();
        int index = 0;
        for (int i = 0; i < _x.length; i++) {
            for (int j = 0; j < _y.length; j++) {
                double[] arr = new double[3];
                arr[0] = _x[i];
                arr[1] = _y[j];
                arr[2] = data[j][i];
                matrix[index++] = arr;
            }
        }
        trainData.setData(matrix);
    }
}
